
***************************************************
*Table A.1
***************************************************


forvalues year=2000/2006 {
local year_plus=`year'+1
tempfile age_tjek`year'
use "$temp/bef_red2_`year'", clear /* $data_do/bef_red.do */ 

keep pnr foed_dagl ie_type edul eduf fm_markl fm_markf d_childl d_childf civstl civstf

keep if ie_type==1 

if `year'==1999 local day1=mdy(1,3,1999)
if `year'==2000 local day1=mdy(1,3,2000)
if `year'==2001 local day1=mdy(1,1,2001)
if `year'==2002 local day1=mdy(12,31,2001)
if `year'==2003 local day1=mdy(12,30,2002)
if `year'==2004 local day1=mdy(12,29,2003)
if `year'==2005 local day1=mdy(1,3,2005)
if `year'==2006 local day1=mdy(1,2,2006)
if `year'==2007 local day1=mdy(1,1,2007)

if `year'==2000 local day2=mdy(1,1,2001)
if `year'==2001 local day2=mdy(12,31,2001)
if `year'==2002 local day2=mdy(12,30,2002)
if `year'==2003 local day2=mdy(12,29,2003)
if `year'==2004 local day2=mdy(1,3,2005)
if `year'==2005 local day2=mdy(1,2,2006)
if `year'==2006 local day2=mdy(1,1,2007)

g age_start=((`day1') -foed_dagl+7)  /365.25
g age_slut =((`day2') -foed_dagl)/365.25

g age_in=age_start<29 & age_slut>=21
keep if age_in==1
g e=1
collapse age_start age_slut foed_dagl, by(pnr)
di `year'
count

g age_any=.
forvalues a=21/28 {
g       age`a'=.
replace age`a'=1 if floor(age_start)==`a' | floor(age_slut)==`a'
sum age`a'
replace age_any=1 if age`a'==1
}
sum age_any
save `age_tjek`year''
}

use `age_tjek2000', clear
forvalues year=2001/2006 {
append using `age_tjek`year''
}

collapse age_start age_slut age2* age_any foed_dagl, by(pnr)

rename age_any age29

matrix X=(.,.)
forvalues a=21/29 {
matrix A=(`a')
sum age`a'
matrix B=(r(N))
matrix C=(A,B)
matrix X=X\C
}

***********************************************************************************


forvalues year=2000/2006 {
local year_plus=`year'+1
tempfile age_tjek`year'
use "$temp/baseline_2_`year'", clear /* $data_do/baseline.do */

keep pnr foed_dagl ie_type edul eduf fm_markl fm_markf d_childl d_childf civstl civstf age
g age_q=floor( (age-floor(age))*12)*(1/12) + floor(age)
keep if age_q>=21 & age_q<29


keep if ie_type==1 
keep if edul=="10" 
keep if eduf=="10" 

g fm_mark_ny=fm_markl!=6 | fm_markf!=6 
g civst_ny=civstl!="U"   | civstf!="U" 
g d_child_ny=d_childl==1 | d_childf==1 

g e=1

collapse  (sum) e fm_mark_ny civst_ny d_child_ny , by(pnr age_q)
di `year'
count

g age_any=.
g fm_mark_any=.
g civst_any=.
g d_child_any=.
g drop_any=.

forvalues a=21/28 {
g       age`a'=.
replace age`a'=1 if floor(age_q)==`a' 
replace age_any=1 if age`a'==1

g fm_mark`a'=.
replace fm_mark`a'=1 if (fm_mark_ny!=0) & age`a'==1
replace fm_mark_any=1 if fm_mark`a'==1

g civst`a'=.
replace civst`a'=1 if (civst_ny!=0) & age`a'==1
replace civst_any=1 if civst`a'==1

g d_child`a'=.
replace d_child`a'=1 if (d_child_ny!=0) & age`a'==1
replace d_child_any=1 if d_child`a'==1

g drop`a'=.
replace drop`a'=1 if (fm_mark`a' ==1 | civst`a'==1 | d_child`a'==1) & age`a'==1
replace drop_any=1 if drop`a'==1
}
save `age_tjek`year''
}

use `age_tjek2000', clear
forvalues year=2001/2006 {
append using `age_tjek`year''
}

replace e=1
collapse (sum) age2* age_any fm_mark2* fm_mark_any civst2* civst_any d_child2* d_child_any drop2* drop_any, by(pnr)

rename (age_any fm_mark_any civst_any d_child_any drop_any) (age29 fm_mark29 civst29 d_child29 drop29)

matrix Y=(.,.,.,.,.,.,.)
forvalues a=21/29 {
matrix A=(`a')

replace age`a'=. if age`a'==0
sum age`a'
matrix B=(r(N))
matrix C=(r(sum))

replace fm_mark`a'=. if fm_mark`a'==0
sum fm_mark`a'
matrix D=(r(sum))

replace civst`a'=. if civst`a'==0
sum civst`a'
matrix E=(r(sum))

replace d_child`a'=. if d_child`a'==0
sum d_child`a'
matrix F=(r(sum))

replace drop`a'=. if drop`a'==0
sum drop`a'
matrix G=(r(sum))

matrix H=(A,B,C,D,E,F,G)
matrix Y=Y\H
}

***********************************************************************************


forvalues year=2000/2006 {
local year_plus=`year'+1
tempfile age_tjek`year'
use "$temp/baseline_2_`year'", clear /* $data_do/baseline.do */

keep pnr foed_dagl ie_type edul eduf fm_markl fm_markf d_childl d_childf civstl civstf age
g age_q=floor( (age-floor(age))*12)*(1/12) + floor(age)
keep if age_q>=21 & age_q<29

keep if ie_type==1 
keep if edul=="10" 
keep if eduf=="10" 
keep if fm_markl==6
keep if fm_markf==6 
keep if d_childl==0 
keep if d_childf==0 
keep if civstl=="U" 
keep if civstf=="U" 

g e=1

collapse  (sum) e , by(pnr age_q)
di `year'
count

g age_any=.

forvalues a=21/28 {
g       age`a'=.
replace age`a'=1 if floor(age_q)==`a' 
replace age_any=1 if age`a'==1
}
save `age_tjek`year''
}

use `age_tjek2000', clear
forvalues year=2001/2006 {
append using `age_tjek`year''
}

replace e=1
collapse (sum) age2* age_any, by(pnr)

rename (age_any) (age29)

matrix Z=(.,.,.)
forvalues a=21/29 {
matrix A=(`a')

replace age`a'=. if age`a'==0
sum age`a'
matrix B=(r(N))
matrix C=(r(sum))

matrix D=(A,B,C)
matrix Z=Z\D
}

capture drop Z*
svmat Z

matrix Q=(X,Y,Z)

capture drop Q*
svmat Q

drop Q3 Q10

preserve
capture drop a1_*
forvalues a1_=1/13 {
capture drop tab_a1_`a1_'
g tab_a1_`a1_'=.
}
replace tab_a1_1=Q1
replace tab_a1_2=Q2
replace tab_a1_4=Q4/Q2
replace tab_a1_6=Q4
replace tab_a1_7=Q5
replace tab_a1_8=Q6/Q5
replace tab_a1_9=Q7/Q5
replace tab_a1_10=Q8/Q5
replace tab_a1_11=Q9/Q5
replace tab_a1_12=Q11
replace tab_a1_13=Q12

keep tab_a1_*
keep if tab_a1_1!=. 
replace tab_a1_1=2128 if tab_a1_1==29
save "$tables/tableA1" , replace
restore

***************************************************
*end: Table A.1
***************************************************
